/*
 * RenderTarget.h
 *
 *  Created on: 2010-09-30
 *      Author: michal
 */

#ifndef RENDERTARGET_H_
#define RENDERTARGET_H_

#include "EasyBMP.h"

struct RT_Pixel
{
	unsigned char R, G, B;
};

class RT_BMP
{
private:
	BMP _bmp;

	int _width;
	int _height;

public:
	RT_BMP(int width, int height) :
		_width(width), _height(height)
	{
		_bmp.SetSize(width, height);
	}

	void WriteToFile(const char * filename)
	{
		_bmp.WriteToFile(filename);
	}

	// ##### interface necessary for class to be used as a rendertarget in Tracer class
	__forceinline void SetPixel(int x, int y, RT_Pixel pixel)
	{
		RGBApixel p;
		p.Red = pixel.R;
		p.Green = pixel.G;
		p.Blue = pixel.B;
		p.Alpha = 255;
		_bmp.SetPixel(x, y, p);
	}

	int GetWidth()
	{
		return _width;
	}
	int GetHeight()
	{
		return _height;
	}

	// #####
};

class RT_Memory
{
private:
	RT_Pixel (* _pixels);
	int _width;
	int _height;

public:
	RT_Memory(int width, int height) :
		_width(width), _height(height)
	{
		_pixels = new RT_Pixel[width * height];
	}

	~RT_Memory()
	{
		delete _pixels;
	}

	RT_Pixel * GetPixels()
	{
		return _pixels;
	}

	// ##### interface necessary for class to be used as a rendertarget in Tracer class
	void SetPixel(int x, int y, RT_Pixel pixel)
	{
		int start = (_height - y - 1) * _width + x;
		_pixels[start].R = pixel.R;
		_pixels[start].G = pixel.G;
		_pixels[start].B = pixel.B;
	}

	int GetWidth()
	{
		return _width;
	}
	int GetHeight()
	{
		return _height;
	}

	// #####
};

#endif /* RENDERTARGET_H_ */
